/**
 * Created by wangyg 
 * on 2017/7/11 19:48
 */

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * Created by wangyg on 2017/7/11.
 */
public class GetJd {

	public static void main(String[] args) throws FileNotFoundException {
		File file =new File("C:\\Users\\wangyg\\Desktop\\11.txt");
		FileOutputStream fop = new FileOutputStream(file);
		long time = System.currentTimeMillis();
		//		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < 20000; i++) {
			String s =
					"https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98vv7321&productId=4879844&score=0&sortType=5&isShadowSku=0&rid=0&fold=1&pageSize=15&page="
							+ i;
			//            HttpClient client=new HttpClient();

			try {
				// 根据地址获取请求
				HttpGet request = new HttpGet(s);//这里发送get请求
				// 获取当前客户端对象
				HttpClient httpClient = new DefaultHttpClient();
				// 通过请求对象获取响应对象
				HttpResponse response = httpClient.execute(request);

				// 判断网络连接状态码是否正常(0--200都数正常)
				if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
					String s1 = EntityUtils.toString(response.getEntity(), "utf-8");
					//					sb.append();
					fop.write(s1.getBytes());
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			//			System.out.println(sb.toString());
			//....result是用户信息,站内业务以及具体的json转换这里也不写了...
		}
		System.out.println("Total time is :"+(System.currentTimeMillis()-time));
	}

}

